#ifndef _DBBSINGLETON_H_
#define _DBBSINGLETON_H_

#include "debug/dbbassert.h"

//------------------------------------------------------------------------------
#define DeclareTLSingleton(type) \
public: \
	ThreadLocal static type * ms_singleton; \
	static type * GetSingleton() { dbbassert(0 != ms_singleton); return ms_singleton; }; \
	static bool HasSingleton() { return 0 != ms_singleton; }; \
private:

#define DeclareSingleton(type) \
public: \
	static type * ms_singleton; \
	static type * GetSingleton() { dbbassert(0 != ms_singleton); return ms_singleton; }; \
	static bool HasSingleton() { return 0 != ms_singleton; }; \
private:

#define ImplementTLSingleton(type) \
	ThreadLocal type * type::ms_singleton = 0;

#define ImplementSingleton(type) \
	type * type::ms_singleton = 0;

#define ConstructSingleton \
	dbbassert(0 == ms_singleton); ms_singleton = this;


#define DestructSingleton \
	dbbassert(ms_singleton); ms_singleton = 0;


#endif